<template>
  <div ref="main" style="width: 1200px;height:800px;margin: 0 auto;" />
</template>

<script>
import { getPieData } from '@/api/orderItem'
export default {
  name: 'Dashboard',
  data() {
    return {}
  },
  created() {
  },
  mounted() {
    getPieData().then((response) => {
      const pieData = response.data
      this.initEcharts(pieData)
    })
  },
  methods: {
    initEcharts(pieData) {
      var myChart = this.$echarts.init(this.$refs.main)
      var option = {
        title: {
          text: '读者最喜爱商品分析',
          subtext: '按商品类型',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [{
          name: '占所有商品的',
          type: 'pie',
          radius: '50%',
          data: pieData,
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }]
      }
      option && myChart.setOption(option)
    }
  }
}
</script>
